package Day2025_02_22;

public class Test_MyBlockingQueue {
    public static void main(String[] args) {
        MyBlockingQueue myBlockingQueue = new MyBlockingQueue(100);
        Thread producer = new Thread(() -> {
            int num = 0;
            while (true) {
                try {
                    myBlockingQueue.put(num);
                    System.out.println("产生了元素: " + num);
                    num++;
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        producer.start();
        Thread consumer = new Thread(() -> {
            while (true) {
                try {
                    int take = myBlockingQueue.take();
                    System.out.println("消费了元素: 0" + take);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        consumer.start();
    }
}
